home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2007 June / SAN CD 6-2007 CD-ROM 25.iso / pc / Software / AstroGrav_Win / Java / jre1.6.0 / lib / rt.jar / javax / swing / JSpinner.class (.txt) < prev    next >
Encoding:
Java Class File  |  2006-11-29  |  5.8 KB  |  221 lines

  1. package javax.swing;
  2.  
  3. import java.io.IOException;
  4. import java.io.ObjectInputStream;
  5. import java.io.ObjectOutputStream;
  6. import java.io.Serializable;
  7. import java.text.ParseException;
  8. import java.util.HashMap;
  9. import java.util.Map;
  10. import javax.accessibility.Accessible;
  11. import javax.accessibility.AccessibleContext;
  12. import javax.swing.event.ChangeEvent;
  13. import javax.swing.event.ChangeListener;
  14. import javax.swing.plaf.SpinnerUI;
  15.  
  16. public class JSpinner extends JComponent implements Accessible {
  17.    private static final String uiClassID = "SpinnerUI";
  18.    private static final Action DISABLED_ACTION = new DisabledAction((1)null);
  19.    private transient SpinnerModel model;
  20.    private JComponent editor;
  21.    private ChangeListener modelListener;
  22.    private transient ChangeEvent changeEvent;
  23.    private boolean editorExplicitlySet;
  24.  
  25.    public JSpinner(SpinnerModel var1) {
  26.       this.editorExplicitlySet = false;
  27.       this.model = var1;
  28.       this.editor = this.createEditor(var1);
  29.       this.setOpaque(true);
  30.       this.updateUI();
  31.    }
  32.  
  33.    public JSpinner() {
  34.       this(new SpinnerNumberModel());
  35.    }
  36.  
  37.    public SpinnerUI getUI() {
  38.       return (SpinnerUI)this.ui;
  39.    }
  40.  
  41.    public void setUI(SpinnerUI var1) {
  42.       super.setUI(var1);
  43.    }
  44.  
  45.    public String getUIClassID() {
  46.       return "SpinnerUI";
  47.    }
  48.  
  49.    public void updateUI() {
  50.       this.setUI((SpinnerUI)UIManager.getUI(this));
  51.       this.invalidate();
  52.    }
  53.  
  54.    protected JComponent createEditor(SpinnerModel var1) {
  55.       if (var1 instanceof SpinnerDateModel) {
  56.          return new DateEditor(this);
  57.       } else if (var1 instanceof SpinnerListModel) {
  58.          return new ListEditor(this);
  59.       } else {
  60.          return (JComponent)(var1 instanceof SpinnerNumberModel ? new NumberEditor(this) : new DefaultEditor(this));
  61.       }
  62.    }
  63.  
  64.    public void setModel(SpinnerModel var1) {
  65.       if (var1 == null) {
  66.          throw new IllegalArgumentException("null model");
  67.       } else {
  68.          if (!var1.equals(this.model)) {
  69.             SpinnerModel var2 = this.model;
  70.             this.model = var1;
  71.             if (this.modelListener != null) {
  72.                this.model.addChangeListener(this.modelListener);
  73.             }
  74.  
  75.             this.firePropertyChange("model", var2, var1);
  76.             if (!this.editorExplicitlySet) {
  77.                this.setEditor(this.createEditor(var1));
  78.                this.editorExplicitlySet = false;
  79.             }
  80.  
  81.             this.repaint();
  82.             this.revalidate();
  83.          }
  84.  
  85.       }
  86.    }
  87.  
  88.    public SpinnerModel getModel() {
  89.       return this.model;
  90.    }
  91.  
  92.    public Object getValue() {
  93.       return this.getModel().getValue();
  94.    }
  95.  
  96.    public void setValue(Object var1) {
  97.       this.getModel().setValue(var1);
  98.    }
  99.  
  100.    public Object getNextValue() {
  101.       return this.getModel().getNextValue();
  102.    }
  103.  
  104.    public void addChangeListener(ChangeListener var1) {
  105.       if (this.modelListener == null) {
  106.          this.modelListener = new ModelListener(this, (1)null);
  107.          this.getModel().addChangeListener(this.modelListener);
  108.       }
  109.  
  110.       this.listenerList.add(ChangeListener.class, var1);
  111.    }
  112.  
  113.    public void removeChangeListener(ChangeListener var1) {
  114.       this.listenerList.remove(ChangeListener.class, var1);
  115.    }
  116.  
  117.    public ChangeListener[] getChangeListeners() {
  118.       return (ChangeListener[])this.listenerList.getListeners(ChangeListener.class);
  119.    }
  120.  
  121.    protected void fireStateChanged() {
  122.       Object[] var1 = this.listenerList.getListenerList();
  123.  
  124.       for(int var2 = var1.length - 2; var2 >= 0; var2 -= 2) {
  125.          if (var1[var2] == ChangeListener.class) {
  126.             if (this.changeEvent == null) {
  127.                this.changeEvent = new ChangeEvent(this);
  128.             }
  129.  
  130.             ((ChangeListener)var1[var2 + 1]).stateChanged(this.changeEvent);
  131.          }
  132.       }
  133.  
  134.    }
  135.  
  136.    public Object getPreviousValue() {
  137.       return this.getModel().getPreviousValue();
  138.    }
  139.  
  140.    public void setEditor(JComponent var1) {
  141.       if (var1 == null) {
  142.          throw new IllegalArgumentException("null editor");
  143.       } else {
  144.          if (!var1.equals(this.editor)) {
  145.             JComponent var2 = this.editor;
  146.             this.editor = var1;
  147.             if (var2 instanceof DefaultEditor) {
  148.                ((DefaultEditor)var2).dismiss(this);
  149.             }
  150.  
  151.             this.editorExplicitlySet = true;
  152.             this.firePropertyChange("editor", var2, var1);
  153.             this.revalidate();
  154.             this.repaint();
  155.          }
  156.  
  157.       }
  158.    }
  159.  
  160.    public JComponent getEditor() {
  161.       return this.editor;
  162.    }
  163.  
  164.    public void commitEdit() throws ParseException {
  165.       JComponent var1 = this.getEditor();
  166.       if (var1 instanceof DefaultEditor) {
  167.          ((DefaultEditor)var1).commitEdit();
  168.       }
  169.  
  170.    }
  171.  
  172.    private void writeObject(ObjectOutputStream var1) throws IOException {
  173.       var1.defaultWriteObject();
  174.       HashMap var2 = new HashMap(1);
  175.       SpinnerModel var3 = this.getModel();
  176.       if (var3 instanceof Serializable) {
  177.          var2.put("model", var3);
  178.       }
  179.  
  180.       var1.writeObject(var2);
  181.       if (this.getUIClassID().equals("SpinnerUI")) {
  182.          byte var4 = JComponent.getWriteObjCounter(this);
  183.          --var4;
  184.          JComponent.setWriteObjCounter(this, var4);
  185.          if (var4 == 0 && this.ui != null) {
  186.             this.ui.installUI(this);
  187.          }
  188.       }
  189.  
  190.    }
  191.  
  192.    private void readObject(ObjectInputStream var1) throws IOException, ClassNotFoundException {
  193.       var1.defaultReadObject();
  194.       Map var2 = (Map)var1.readObject();
  195.       this.model = (SpinnerModel)var2.get("model");
  196.    }
  197.  
  198.    public AccessibleContext getAccessibleContext() {
  199.       if (this.accessibleContext == null) {
  200.          this.accessibleContext = new AccessibleJSpinner(this);
  201.       }
  202.  
  203.       return this.accessibleContext;
  204.    }
  205.  
  206.    // $FF: synthetic method
  207.    static Action access$200() {
  208.       return DISABLED_ACTION;
  209.    }
  210.  
  211.    // $FF: synthetic method
  212.    static SpinnerModel access$500(JSpinner var0) {
  213.       return var0.model;
  214.    }
  215.  
  216.    // $FF: synthetic method
  217.    static JComponent access$600(JSpinner var0) {
  218.       return var0.editor;
  219.    }
  220. }
  221.